﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Cherry.Agile.Framework;
namespace Cherry.Agile.Security
{
    /// <summary>
    /// 票据
    /// </summary>
    [Serializable]
    public class Token : IToken
    {
        AccountTicket ticket;
        /// <summary>
        /// 
        /// </summary>
        /// <param name="user"></param>
        public Token( User user)
        {
            ticket = new AccountTicket(user);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="value"></param>
        public Token(string value)
        {
            var temp = value.Split('&');
            ticket = new AccountTicket();
            ticket.Identity = temp[0];
            ticket.Id = temp[1].ToInt();
            ticket.Type = temp[2].ToInt();
            
        }

        /// <summary>
        /// 
        /// </summary>
        public ITicket Value
        {
            get { return ticket; }
        }


        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public string GetTicketString()
        {
            return string.Format("{0}&{1}&{2}", ticket.Identity, ticket.Id, ticket.Type);
        }

    }
}
